<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>栏目修改</title>
    <meta name="keywords" content="后台用户添加">
    <meta name="description" content="后台用户添加">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/Public/Admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/font-awesome.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/Public/Admin/css/animate.css" rel="stylesheet">
    <link href="/Public/Admin/js/plugins/layer/skin/default/layer.css" rel="stylesheet">
    <link href="/Public/Admin/css/style.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/switchery/switchery.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>修改栏目</h5>
                </div>
                <div class="ibox-content">
                    <form method="post" id="formadd" name="formadd" class="form-horizontal" action="<?php echo U('Art/editsave');?>">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">栏目名称：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="artname" name="artname" value="<?php echo ($getInfo["artname"]); ?>">
                            </div>
                            <input type="hidden" name="id" value="<?php echo ($getInfo["id"]); ?>">
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">上级分类：</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="pid" id="pid">
                                    <option value="0">1</option>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="sort" name="sort" value="<?php echo ($getInfo["sort"]); ?>">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">关键词：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="keywords" name="keywords" value="<?php echo ($getInfo["keywords"]); ?>">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述：</label>
                            <div class="col-sm-10">
                                <textarea name="description" id="description" rows="8" cols="180"><?php echo ($getInfo["description"]); ?></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">状态：</label>
                            <div class="col-sm-10">
             <input type="checkbox" name="status" id="status" value="1" class="js-switch" <?php if($getInfo['status'] == 1): ?>checked<?php endif; ?>> 正常
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit">保存内容</button>
                                <a class="btn btn-white" href="javascript:history.go(-1)">取消</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/Public/Admin/js/jquery.min.js"></script>
<script src="/Public/Admin/js/bootstrap.min.js"></script>
<script src="/Public/Admin/js/plugins/switchery/switchery.js"></script>
<script src="/Public/Admin/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/Public/Admin/js/plugins/validate/messages_zh.min.js"></script>
<script src="/Public/Admin/js/plugins/layer/layer.js"></script>
<script src="/Public/Admin/js/comment.js"></script>
<script>
    $(function(){
        $('#formadd').validate({
            //相当于在input中添加
            //<input type="text" class="form-control" id="username" name="username" id="username" required>
            //前台提交验证表单
            rules:{
                artname:"required",
                // pid:"required", 
                sort:"required", 
                keywords:"required", 
                description:"required"
            },
            messages:{
                artname:'栏目名不能为空!',
                // pid:'请选择分类!',
                sort:'排序不能为空!',
                keywords:'关键词不能为空!',
                description:'描述不能为空!',

            },
            //提交成功后执行
            submitHandler:function(form){
                var objNames = $(form).serializeArray();//从form表单input的内容序列化数组的形式传过来
                console.log(objNames);
                //[0:object name:'username' value:'dsfsad', 0:object name:'password' value:'dsfsad',....]
                var dataNames = new Object();//创建对象
                //循环遍历传递过来组成数组
                $.each(objNames,function(key,val){
                    dataNames[val.name] = val.value;
                });
                $.ajax({
                    url:$(form).attr('action'),//地址是通过form 的action
                    type:'post',
                    dataType:'json',
                    data:dataNames,//传的对象
                    success:function(data){
                        if(data.status < 1){
                            comment.error(data.mess);
                        }else{
                            comment.success(data.mess,"<?php echo U('Art/index');?>");
                        }
                    }
                });

            }
        });
    });
    var elem = document.querySelector('.js-switch');
    var init = new Switchery(elem,{ size: 'small', jackColor: '#9decff' });  
</script>
</body>
</html>